import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import encrypt from '@/utils/encrypt';
import {render} from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '归属项目',
    align: 'center',
    dataIndex: 'subProjectName',
  },
  {
    title: '通知人姓名',
    align: 'center',
    dataIndex: 'noticeName',
  },
  {
    title: '邮箱',
    align: 'center',
    dataIndex: 'email',
    format: (text) => {
      return encrypt.decrypt(text);
    },
  },
  {
    title: '手机号',
    align: 'center',
    dataIndex: 'phone',
    format: (text) => {
      return encrypt.decrypt(text);
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '归属项目',
    field: 'subProject',
    component: 'JSelectDept',
    componentProps: ({ formActionType, formModel }) => {
      return {
        sync: false,
        checkStrictly: true,
        multiple: false,
        defaultExpandLevel: 2,
        onSelect: (options, values) => {
          const { updateSchema } = formActionType;
          //所属部门修改后更新负责部门下拉框数据
          updateSchema([
            {
              field: 'departIds',
              componentProps: { options },
            },
          ]);
          //update-begin---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
          if(!values){
            formModel.departIds = [];
            return;
          }
          //update-end---author:wangshuai---date:2024-05-11---for:【issues/1222】用户编辑界面“所属部门”与“负责部门”联动出错整---
          //所属部门修改后更新负责部门数据
          formModel.departIds && (formModel.departIds = formModel.departIds.filter((item) => values.value.indexOf(item) > -1));
        },
      };
    },
  },
  {
    label: '通知人姓名',
    field: 'noticeName',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入通知人姓名!' }];
    },
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入邮箱!' }];
    },
  },
  {
    label: '手机号',
    field: 'phone',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入手机号!' }];
    },
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  noticeName: { title: '通知人姓名', order: 0, view: 'text', type: 'string' },
  email: { title: '邮箱', order: 1, view: 'text', type: 'string' },
  phone: { title: '手机号', order: 2, view: 'text', type: 'string' },
  status: {
    title: '通知方式二进制;0-全部关闭,下标0-手机,下标1-邮箱',
    order: 3,
    view: 'text',
    type: 'string',
  },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
